// 依赖和基础信息
const ethers = require('ethers')
const Token = require('../Token.json')

const ganachePrivateKey =
  '0x700c472fef576757270df5068e0ec7152e7307000cfe3fbf5d15be43bde55230'
const userAddress = '0xac9199717985cDaC98e5832370B208B8a33A50Ef'

// 连接provider
let local_provider = new ethers.providers.JsonRpcProvider(
  'http://localhost:8545',
)
let naturelab_provider = new ethers.providers.JsonRpcProvider(
  'http://47.243.92.131:8545',
)

let wallet = new ethers.Wallet(ganachePrivateKey, local_provider)
console.log(`Loaded wallet ${wallet.address}`)

// 合约地址，请替换成实际部署的地址
const contractAddress = '0x4EB08c5713C47A2a463Abf0cD5B6a28514c567Ad'
const abi = Token.abi

// 代币转账方法： 三个参数分别是合约地址、收款人地址、转账数量（单位是wei)
async function transfer(contractAddress, to, amount) {
  let contractWithSigner = new ethers.Contract(contractAddress, abi, wallet)

  const result = await contractWithSigner.transfer(to, amount)
  console.log('transfer hash:', result.hash)
  return
}

transfer(contractAddress, userAddress, 10)
